package codetop.dp;

public class Code053 {
    public int maxSubArray(int[] nums) {
        int len=nums.length;
        int []dp=new int[len];
        dp[0]=nums[0];
        int res=dp[0];
        for (int i = 1; i < len; i++) {
            dp[i]=dp[i-1]>0?dp[i-1]+nums[i]:nums[i];
            res=Math.max(dp[i],res);
        }
        return res;
    }
}
